// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyMeshManagementAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyMeshManagementAttributes
//
// Purpose:
//   Global variables controlling reading and conversion of non-standard meshes
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a MeshManagementAttributes.
//
struct MeshManagementAttributesObject
{
    PyObject_HEAD
    MeshManagementAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewMeshManagementAttributes(int);
std::string
PyMeshManagementAttributes_ToString(const MeshManagementAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    {   const doubleVector &discretizationTolerance = atts->GetDiscretizationTolerance();
        snprintf(tmpStr, 1000, "%sdiscretizationTolerance = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < discretizationTolerance.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", discretizationTolerance[i]);
            str += tmpStr;
            if(i < discretizationTolerance.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &discretizationToleranceX = atts->GetDiscretizationToleranceX();
        snprintf(tmpStr, 1000, "%sdiscretizationToleranceX = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < discretizationToleranceX.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", discretizationToleranceX[i]);
            str += tmpStr;
            if(i < discretizationToleranceX.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &discretizationToleranceY = atts->GetDiscretizationToleranceY();
        snprintf(tmpStr, 1000, "%sdiscretizationToleranceY = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < discretizationToleranceY.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", discretizationToleranceY[i]);
            str += tmpStr;
            if(i < discretizationToleranceY.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &discretizationToleranceZ = atts->GetDiscretizationToleranceZ();
        snprintf(tmpStr, 1000, "%sdiscretizationToleranceZ = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < discretizationToleranceZ.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", discretizationToleranceZ[i]);
            str += tmpStr;
            if(i < discretizationToleranceZ.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    const char *discretizationMode_names = "Uniform, Adaptive, MultiPass";
    switch (atts->GetDiscretizationMode())
    {
      case MeshManagementAttributes::Uniform:
          snprintf(tmpStr, 1000, "%sdiscretizationMode = %sUniform  # %s\n", prefix, prefix, discretizationMode_names);
          str += tmpStr;
          break;
      case MeshManagementAttributes::Adaptive:
          snprintf(tmpStr, 1000, "%sdiscretizationMode = %sAdaptive  # %s\n", prefix, prefix, discretizationMode_names);
          str += tmpStr;
          break;
      case MeshManagementAttributes::MultiPass:
          snprintf(tmpStr, 1000, "%sdiscretizationMode = %sMultiPass  # %s\n", prefix, prefix, discretizationMode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetDiscretizeBoundaryOnly())
        snprintf(tmpStr, 1000, "%sdiscretizeBoundaryOnly = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sdiscretizeBoundaryOnly = 0\n", prefix);
    str += tmpStr;
    if(atts->GetPassNativeCSG())
        snprintf(tmpStr, 1000, "%spassNativeCSG = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%spassNativeCSG = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
MeshManagementAttributes_Notify(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizationTolerance(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetDiscretizationTolerance() = vec;
    // Mark the discretizationTolerance in the object as modified.
    obj->data->SelectDiscretizationTolerance();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizationTolerance(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the discretizationTolerance.
    const doubleVector &discretizationTolerance = obj->data->GetDiscretizationTolerance();
    PyObject *retval = PyTuple_New(discretizationTolerance.size());
    for(size_t i = 0; i < discretizationTolerance.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(discretizationTolerance[i]));
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizationToleranceX(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetDiscretizationToleranceX() = vec;
    // Mark the discretizationToleranceX in the object as modified.
    obj->data->SelectDiscretizationToleranceX();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizationToleranceX(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the discretizationToleranceX.
    const doubleVector &discretizationToleranceX = obj->data->GetDiscretizationToleranceX();
    PyObject *retval = PyTuple_New(discretizationToleranceX.size());
    for(size_t i = 0; i < discretizationToleranceX.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(discretizationToleranceX[i]));
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizationToleranceY(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetDiscretizationToleranceY() = vec;
    // Mark the discretizationToleranceY in the object as modified.
    obj->data->SelectDiscretizationToleranceY();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizationToleranceY(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the discretizationToleranceY.
    const doubleVector &discretizationToleranceY = obj->data->GetDiscretizationToleranceY();
    PyObject *retval = PyTuple_New(discretizationToleranceY.size());
    for(size_t i = 0; i < discretizationToleranceY.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(discretizationToleranceY[i]));
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizationToleranceZ(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetDiscretizationToleranceZ() = vec;
    // Mark the discretizationToleranceZ in the object as modified.
    obj->data->SelectDiscretizationToleranceZ();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizationToleranceZ(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the discretizationToleranceZ.
    const doubleVector &discretizationToleranceZ = obj->data->GetDiscretizationToleranceZ();
    PyObject *retval = PyTuple_New(discretizationToleranceZ.size());
    for(size_t i = 0; i < discretizationToleranceZ.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(discretizationToleranceZ[i]));
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizationMode(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid discretizationMode value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Uniform";
        ss << ", Adaptive";
        ss << ", MultiPass";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the discretizationMode in the object.
    obj->data->SetDiscretizationMode(MeshManagementAttributes::DiscretizationModes(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizationMode(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetDiscretizationMode()));
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetDiscretizeBoundaryOnly(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the discretizeBoundaryOnly in the object.
    obj->data->SetDiscretizeBoundaryOnly(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetDiscretizeBoundaryOnly(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetDiscretizeBoundaryOnly()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MeshManagementAttributes_SetPassNativeCSG(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the passNativeCSG in the object.
    obj->data->SetPassNativeCSG(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshManagementAttributes_GetPassNativeCSG(PyObject *self, PyObject *args)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetPassNativeCSG()?1L:0L);
    return retval;
}



PyMethodDef PyMeshManagementAttributes_methods[MESHMANAGEMENTATTRIBUTES_NMETH] = {
    {"Notify", MeshManagementAttributes_Notify, METH_VARARGS},
    {"SetDiscretizationTolerance", MeshManagementAttributes_SetDiscretizationTolerance, METH_VARARGS},
    {"GetDiscretizationTolerance", MeshManagementAttributes_GetDiscretizationTolerance, METH_VARARGS},
    {"SetDiscretizationToleranceX", MeshManagementAttributes_SetDiscretizationToleranceX, METH_VARARGS},
    {"GetDiscretizationToleranceX", MeshManagementAttributes_GetDiscretizationToleranceX, METH_VARARGS},
    {"SetDiscretizationToleranceY", MeshManagementAttributes_SetDiscretizationToleranceY, METH_VARARGS},
    {"GetDiscretizationToleranceY", MeshManagementAttributes_GetDiscretizationToleranceY, METH_VARARGS},
    {"SetDiscretizationToleranceZ", MeshManagementAttributes_SetDiscretizationToleranceZ, METH_VARARGS},
    {"GetDiscretizationToleranceZ", MeshManagementAttributes_GetDiscretizationToleranceZ, METH_VARARGS},
    {"SetDiscretizationMode", MeshManagementAttributes_SetDiscretizationMode, METH_VARARGS},
    {"GetDiscretizationMode", MeshManagementAttributes_GetDiscretizationMode, METH_VARARGS},
    {"SetDiscretizeBoundaryOnly", MeshManagementAttributes_SetDiscretizeBoundaryOnly, METH_VARARGS},
    {"GetDiscretizeBoundaryOnly", MeshManagementAttributes_GetDiscretizeBoundaryOnly, METH_VARARGS},
    {"SetPassNativeCSG", MeshManagementAttributes_SetPassNativeCSG, METH_VARARGS},
    {"GetPassNativeCSG", MeshManagementAttributes_GetPassNativeCSG, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
MeshManagementAttributes_dealloc(PyObject *v)
{
   MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *MeshManagementAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyMeshManagementAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "discretizationTolerance") == 0)
        return MeshManagementAttributes_GetDiscretizationTolerance(self, NULL);
    if(strcmp(name, "discretizationToleranceX") == 0)
        return MeshManagementAttributes_GetDiscretizationToleranceX(self, NULL);
    if(strcmp(name, "discretizationToleranceY") == 0)
        return MeshManagementAttributes_GetDiscretizationToleranceY(self, NULL);
    if(strcmp(name, "discretizationToleranceZ") == 0)
        return MeshManagementAttributes_GetDiscretizationToleranceZ(self, NULL);
    if(strcmp(name, "discretizationMode") == 0)
        return MeshManagementAttributes_GetDiscretizationMode(self, NULL);
    if(strcmp(name, "Uniform") == 0)
        return PyInt_FromLong(long(MeshManagementAttributes::Uniform));
    if(strcmp(name, "Adaptive") == 0)
        return PyInt_FromLong(long(MeshManagementAttributes::Adaptive));
    if(strcmp(name, "MultiPass") == 0)
        return PyInt_FromLong(long(MeshManagementAttributes::MultiPass));

    if(strcmp(name, "discretizeBoundaryOnly") == 0)
        return MeshManagementAttributes_GetDiscretizeBoundaryOnly(self, NULL);
    if(strcmp(name, "passNativeCSG") == 0)
        return MeshManagementAttributes_GetPassNativeCSG(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyMeshManagementAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyMeshManagementAttributes_methods[i].ml_name),
                PyString_FromString(PyMeshManagementAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyMeshManagementAttributes_methods, self, name);
}

int
PyMeshManagementAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "discretizationTolerance") == 0)
        obj = MeshManagementAttributes_SetDiscretizationTolerance(self, args);
    else if(strcmp(name, "discretizationToleranceX") == 0)
        obj = MeshManagementAttributes_SetDiscretizationToleranceX(self, args);
    else if(strcmp(name, "discretizationToleranceY") == 0)
        obj = MeshManagementAttributes_SetDiscretizationToleranceY(self, args);
    else if(strcmp(name, "discretizationToleranceZ") == 0)
        obj = MeshManagementAttributes_SetDiscretizationToleranceZ(self, args);
    else if(strcmp(name, "discretizationMode") == 0)
        obj = MeshManagementAttributes_SetDiscretizationMode(self, args);
    else if(strcmp(name, "discretizeBoundaryOnly") == 0)
        obj = MeshManagementAttributes_SetDiscretizeBoundaryOnly(self, args);
    else if(strcmp(name, "passNativeCSG") == 0)
        obj = MeshManagementAttributes_SetPassNativeCSG(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
MeshManagementAttributes_print(PyObject *v, FILE *fp, int flags)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)v;
    fprintf(fp, "%s", PyMeshManagementAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
MeshManagementAttributes_str(PyObject *v)
{
    MeshManagementAttributesObject *obj = (MeshManagementAttributesObject *)v;
    return PyString_FromString(PyMeshManagementAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *MeshManagementAttributes_Purpose = "Global variables controlling reading and conversion of non-standard meshes";
#else
static char *MeshManagementAttributes_Purpose = "Global variables controlling reading and conversion of non-standard meshes";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(MeshManagementAttributesType,         \
                  "MeshManagementAttributes",           \
                  MeshManagementAttributesObject,       \
                  MeshManagementAttributes_dealloc,     \
                  MeshManagementAttributes_print,       \
                  PyMeshManagementAttributes_getattr,   \
                  PyMeshManagementAttributes_setattr,   \
                  MeshManagementAttributes_str,         \
                  MeshManagementAttributes_Purpose,     \
                  MeshManagementAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
MeshManagementAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &MeshManagementAttributesType
         || Py_TYPE(other) != &MeshManagementAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    MeshManagementAttributes *a = ((MeshManagementAttributesObject *)self)->data;
    MeshManagementAttributes *b = ((MeshManagementAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static MeshManagementAttributes *defaultAtts = 0;
static MeshManagementAttributes *currentAtts = 0;

static PyObject *
NewMeshManagementAttributes(int useCurrent)
{
    MeshManagementAttributesObject *newObject;
    newObject = PyObject_NEW(MeshManagementAttributesObject, &MeshManagementAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new MeshManagementAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new MeshManagementAttributes(*defaultAtts);
    else
        newObject->data = new MeshManagementAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapMeshManagementAttributes(const MeshManagementAttributes *attr)
{
    MeshManagementAttributesObject *newObject;
    newObject = PyObject_NEW(MeshManagementAttributesObject, &MeshManagementAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (MeshManagementAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
MeshManagementAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewMeshManagementAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef MeshManagementAttributesMethods[] = {
    {"MeshManagementAttributes", MeshManagementAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *MeshManagementAttributesObserver = 0;

std::string
PyMeshManagementAttributes_GetLogString()
{
    std::string s("MeshManagementAtts = MeshManagementAttributes()\n");
    if(currentAtts != 0)
        s += PyMeshManagementAttributes_ToString(currentAtts, "MeshManagementAtts.", true);
    return s;
}

static void
PyMeshManagementAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("MeshManagementAtts = MeshManagementAttributes()\n");
        s += PyMeshManagementAttributes_ToString(currentAtts, "MeshManagementAtts.", true);
        cb(s);
    }
}

void
PyMeshManagementAttributes_StartUp(MeshManagementAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyMeshManagementAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(MeshManagementAttributesObserver == 0)
    {
        MeshManagementAttributesObserver = new ObserverToCallback(subj,
            PyMeshManagementAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyMeshManagementAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete MeshManagementAttributesObserver;
    MeshManagementAttributesObserver = 0;
}

PyMethodDef *
PyMeshManagementAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return MeshManagementAttributesMethods;
}

bool
PyMeshManagementAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &MeshManagementAttributesType);
}

MeshManagementAttributes *
PyMeshManagementAttributes_FromPyObject(PyObject *obj)
{
    MeshManagementAttributesObject *obj2 = (MeshManagementAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyMeshManagementAttributes_New()
{
    return NewMeshManagementAttributes(0);
}

PyObject *
PyMeshManagementAttributes_Wrap(const MeshManagementAttributes *attr)
{
    return WrapMeshManagementAttributes(attr);
}

void
PyMeshManagementAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    MeshManagementAttributesObject *obj2 = (MeshManagementAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyMeshManagementAttributes_SetDefaults(const MeshManagementAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new MeshManagementAttributes(*atts);
}

